package com.zj.springcloud.config;

import feign.Logger;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class ConfigBean { //@Configuration -- spring applicationContext.xml
    /**
     * 注册一个远程访问的bean
     * @return
     */
//    @Bean
//    public RestTemplate getRestTemplate(){
//        return new RestTemplate();
//    }

    /**
     * 配置负载均衡实现RestTemplate
     * IRule
     *      AvailabilityFilteringRule 会先过滤掉，跳闸，访问故障的服务~，对剩下的轮训
     *      RoundRobinRule 轮询
     *      RandomRule 随机
     *      RetryRule 重试，服务失败会在指定的时间内重试
     */
    @Bean
    @LoadBalanced  //ribbon负载均衡，只加一个注解就ok
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }


    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }


}
